package com.example.boardroom.demo.room;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;

import java.util.List;

@Dao
public interface HardwareControlDao {


    @Query("SELECT * FROM hardwarecontroltable WHERE id IN (:ids)")
    List<HardwareControlTable> loadAllByIds(int[] ids);

    @Insert
    void insertAll(HardwareControlTable... tables);

    @Delete
    void delete(HardwareControlTable table);

    @Query("delete from HardwareControlTable")
    void clear();


    /**
     * @param id 我们在获取room数据库中的结果，如果需要针对某个字段进行排序和sqlite语句一样，通过order by
     *           <p>
     *           进行排序就可以实现正序和倒叙了。
     *           <p>
     *           示例：通过表中的time字段，进行倒叙查询。时间最大的显示在第一项。
     */
    @Query("SELECT * FROM HardwareControlTable WHERE id = :id ORDER BY timeStamp desc")
    List<HardwareControlTable> getDevicesById(int id);

    @Query("SELECT COUNT(timeStamp) FROM HardwareControlTable")
    Integer getRowCount();

    /**
     * @param id 正序查询
     * @return
     */
    @Query("SELECT * FROM HardwareControlTable WHERE id = :id ")
    List<HardwareControlTable> getDevicesById2(int id);


    @Query("SELECT * FROM HardwareControlTable WHERE id = :id ")
    List<HardwareControlTable> getDevicesById3(int id);


    @Query("SELECT * FROM HardwareControlTable WHERE timeStamp BETWEEN :threeHourLate and :nowTime")
    List<HardwareControlTable> getThreeTimeDatas(String threeHourLate, String nowTime);


    @Query("SELECT * FROM HardwareControlTable WHERE id = :id and timeStamp BETWEEN :threeHourLate and :nowTime")
    List<HardwareControlTable> getDevicesByIdAndTime(int id, String threeHourLate, String nowTime);

}
